package com.noahplat.sms.controller;

import com.noahplat.common.utils.Result;
import com.noahplat.sms.pojo.Whiteip;
import com.noahplat.sms.service.SmsService;
import com.noahplat.sms.service.WhiteIpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;


/**
 * 作者：李景星
 * 描述：短信平台接口
 * 时间：2021-01-27
 */
@RequestMapping("/api/whiteip")
@RestController
@Validated
public class WhiteIpController {

    @Autowired
    private WhiteIpService whiteIpService;

    /**
     * 添加白名单
     * @param whiteip
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-sms:WhiteIpController:addWhiteIp')")
    @PostMapping("/addWhiteIp")
    public Result addWhiteIp(@RequestBody Whiteip whiteip){
        return whiteIpService.addWhiteIp(whiteip);
    }

    /**
     * 获取白名单
     * @param page
     * @param limit
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-sms:WhiteIpController:getWhiteIp')")
    @GetMapping("/getWhiteIp")
    public Result getWhiteIp(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "10")Integer limit){
        return whiteIpService.getWhiteIp(page, limit);
    }

    /**
     * 删除白名单
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-sms:WhiteIpController:delWhiteIp')")
    @DeleteMapping("/delWhiteIp")
    public Result delWhiteIp(@NotNull(message = "ID不能为空 ") @Min(value = 1, message = "Id不能为空")Long id){
        return whiteIpService.delWhiteIp(id);
    }
}
